<template>
  <div class="notification-containner"  :key="apply.id">
      <van-nav-bar title="申请详情" class="page-nav-bar" left-arrow @click="this.$router.back();" >
      </van-nav-bar>
  
      <div class="loading-wrap" v-if="loading">
          <van-loading color="#3296fa" vertical>加载中</van-loading>
      </div>
  
  
  
  
  
  
  
  
  
  
  <div class="article-detail" v-else-if="apply.text">
      <div class="article-content-card">
        <div class="article-header">
  
     
    <h1 class="title">申请进展</h1>
  </div>
  <van-steps :active="active">
  <van-step>提交申请单</van-step>
  <van-step>管理员审核</van-step>
  <van-step>审核结果反馈</van-step>
</van-steps>
<h2 class="title">申请信息</h2><hr>
   <div  class="article-content">
    申请留言：  {{ apply.text }}
    </div><hr>
    <div   class="article-content">
    回执信息：  {{  apply.status==-1?apply.msg:apply.status==1?'审核通过':'待审核，无回执记录' }}
    </div>
    <div class="article-footer">
      <div class="article-source-card">
        <div class="article-source">{{ apply.clubs.name }}</div>
      </div>
      <div class="article-time-card">
        <div class="article-time">{{ dayjs().to(dayjs(apply.createTime)) }}</div>
      </div>
    </div>
  
  </div>
  
    </div>
  
    <div class="error-wrap" v-else-if="errStatus === 404">
      <van-icon name="failure"></van-icon>
      <p class="text">该资源不存在</p>
      </div>
  
      
    <div class="error-wrap" v-else>
      <van-icon name="failure"></van-icon>
      <p class="text">内容加载失败！</p>
      <van-button class="retry-btn" @click="loadNotification(props.applyId)">点击重试</van-button>
    </div>
  </div>
  </template>
  
  <script>
  import {getApplyById} from '../../api/apply';
  import { onMounted,reactive,toRefs,ref } from 'vue';
  import dayjs from '../../utils/day';
  function useLoadNotification(applyId,state,active){
      const loadNotification= async()=>{
          try{
              const {data}= await getApplyById(applyId);
  
             if(data.code==0){
              state.errStatus=404;
              //文章已经被删除
             }else{
              state.apply=data.data;
              if(state.apply.status!=0){
                active.value=2;
          }
             }
  
          }catch(err){
              //加载失败
          }
          state.loading=false;
  
      };
      onMounted(()=>{
          loadNotification();
      })
  
  }
  export default {
  
      props:{
          applyId:{
              type:String,
              required:true
          },
      
      } ,
      setup(props){
        let active = ref(1);
          const state=reactive({
              apply:{
                createTime:'',
                  text:'',
                  status:'',
                  msg:'',
                  clubs:{
                      name:''
                  }
              },
              loading:true,
              errStatus:0,
          });
          useLoadNotification(props.applyId,state,active);
         return{
          ...toRefs(state),
          dayjs,
          active
         } 
      }
  };
  
  </script>
  
  <style scoped>
  .article-content-card {
    padding: 24px;
    background-color: #fff;
    border-radius: 0px;
    box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.08);
    margin-top: 10px;
  }
  
  .article-source-card {
    background-color: #3f64ca;
    color: #fff;
    padding: 8px 16px;
    border-radius: 16px;
    display: inline-block;
  }
  
  .article-time-card {
    margin-left: 16px;
    display: inline-block;
  }
  .loading-wrap{
      padding: 200px 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #fff;
  }
  .error-wrap{
      padding: 200px 32px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background-color: #fff;
      
  }
  .title-card {
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.1);
  }
  
  .title {
    font-size: 2em;
    font-weight: bold;
    margin: 0;
  }
  
  .article-detail {
      
    padding: 16px;
    background-color: #fff;
  }
  
  .article-header {
       width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 16px;
  }
  
  .title {
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 16px;
  }
  
  .author-card {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #f2f2f2;
    border-radius: 4px;
    padding: 12px 16px;
  }
  
  .author-info {
    display: flex;
    flex-direction: column;
  }
  
  .author-name {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 4px;
  }
  
  .article-date {
    font-size: 12px;
    color: #999;
  }
  
  .article-content {
    line-height: 1.5;
    font-size: 20px;
  }
  
  .article-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    font-size: 14px;
    color: #999;
  }
  
  .article-source {
    margin-right: 16px;
  }
  
  .article-time {
    margin-left: 16px;
  }
  .author-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .author-card .author-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-right: 24px;
  }
  
  .author-card .author-info .author-name {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
  }
  
  .author-card .article-date {
    font-size: 16px;
    color: #999;
  }
  .article-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
  }
  
  .title {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 10px;
  }
  
  .author-card {
    display: flex;
    align-items: center;
    margin-top: 20px;
  }
  
  .author-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 20px;
  }
  
  .author-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  .author-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
  }
  
  .author-name {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 5px;
  }
  
  .author-desc {
    font-size: 14px;
    margin-bottom: 5px;
  }
  
  .article-date {
    font-size: 14px;
    color: #999;
  }
  
  </style>